package edu.hubu.helloworld.fragemnt;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import edu.hubu.helloworld.adapter.FriendAdapter;
import edu.hubu.helloworld.R;
import edu.hubu.helloworld.entity.Friend;

public class FriendFragment extends Fragment {

    // define recycle view
    RecyclerView friendRecycleView;

    // define adapter
    RecyclerView.Adapter<FriendAdapter.FriendViewHolder> friendAdapter;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_friend, container, false);
        init(view);
        return view;
    }

    private void init(View view) {
        List<Friend> friends = new ArrayList<>();
        friends.add(new Friend("森の妖精", R.drawable.king));
        friends.add(new Friend("香蕉君", R.drawable.banana));

        friendRecycleView = view.findViewById(R.id.friend_recycleView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        friendRecycleView.setLayoutManager(linearLayoutManager);

        friendAdapter = new FriendAdapter(friends);
        friendRecycleView.setAdapter(friendAdapter);

    }
}